package cn.bugio.note.feignclient.fallbackfactory;

import cn.bugio.note.common.domain.dto.UserDTO;
import cn.bugio.note.common.vo.ServerResponse;
import cn.bugio.note.feignclient.UserCenterFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author Vincent Vic
 * @version 1.0
 * @Description
 * @since 2021/2/27
 */

@Component
@Slf4j
public class UserCenterFeignClientFallbackFactory implements FallbackFactory<UserCenterFeignClient> {

    @Override
    public UserCenterFeignClient create(Throwable throwable) {
        return (UserCenterFeignClient) (id) -> {
            UserDTO userDTO = new UserDTO();
            log.error("feign exception :" ,throwable);
            return ServerResponse.error("限流或降级" + throwable.getMessage(),userDTO);
        };
    }
}
